package com.wl.wuliu.entity;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wl.wuliu.utils.SecurityUtils;
import com.wl.wuliu.utils.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity基类
 * @Author: gutaozhen
 * @Date: 2022/10/14
 */
public class BaseEntity implements Serializable
{
    private static final long serialVersionUID = 1L;

    private String id;

    /** 创建者 */
    private String createBy;

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /** 更新者 */
    private String updateBy;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    /** 删除标记（0：正常；1：删除；2：审核） */
    @TableLogic
    private String delFlag;

    /** 备注 */
    private String remark;

    /** 请求参数 */
    @TableField(exist = false)
    private Map<String, Object> params;

    /** 批量删除id*/
    @TableField(exist = false)
    private String[] idList;

    public String getCreateBy()
    {
        return createBy;
    }

    public void setCreateBy(String createBy)
    {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getUpdateBy()
    {
        return updateBy;
    }

    public void setUpdateBy(String updateBy)
    {
        this.updateBy = updateBy;
    }

    public Map<String, Object> getParams()
    {
        if (params == null)
        {
            params = new HashMap<>();
        }
        return params;
    }

    public void setParams(Map<String, Object> params)
    {
        this.params = params;
    }

    public String getDelFlag() {

        if (StringUtils.isBlank(delFlag)){
            delFlag = "0";
        }
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String[] getIdList() {
        return idList;
    }

    public void setIdList(String[] idList) {
        this.idList = idList;
    }

    /**
     * 插入之前执行方法，需要手动调用
     */
    public void preInsert(){
        this.setId(IdUtil.fastSimpleUUID());
        this.setCreateTime(new Date());
//        this.setCreateBy(SecurityUtils.getLoginUser().getUser().getId());
        this.setUpdateTime(new Date());
        this.setDelFlag("0");
//        this.setUpdateBy(SecurityUtils.getLoginUser().getUser().getId());
    }

    /**
     * 更新之前执行方法，需要手动调用
     */
    public void preUpdate(){
        this.setUpdateTime(new Date());
//        this.setUpdateBy(SecurityUtils.getLoginUser().getUser().getId());
    }

    public BaseEntity() {
    }

    public BaseEntity(String id) {
        this.id = id;
    }

    /**
     * 删除标记（0：正常；1：删除；）
     */
    public static final String DEL_FLAG_NORMAL = "0";
    public static final String DEL_FLAG_DELETE = "1";

}
